﻿using System;
namespace 第四次
{
    class Program
    {
        static void Main(string[] args)
        {
            float nextTime = 1;
            int i, j, k;
            string time;
            k = 0;
            //输入闹钟运行时间，秒

            Console.WriteLine("设置闹钟运行时间，秒数");
            j = Convert.ToInt32(Console.ReadLine());
            //输入铃响时间
            Console.WriteLine("设置闹钟铃响时间，例如10:20:31");
            time =  Console.ReadLine();

            /***********触发***********/
            EventTest e = new EventTest(); /* 实例化对象,第一次没有触发事件 */
            subscribEvent v = new subscribEvent(); /* 实例化对象 */
            e.ClockDida += new EventTest.ClockHandler(v.printf1); /* 注册 */
            e.ClockAlarm += new EventTest.ClockHandler(v.printf2); /* 注册 */

            Console.WriteLine("闹钟开始嘀嗒嘀嗒嘀嗒嘀嗒");
          
            for (i = 0;i<j;i=k)
            {
                DateTime dt = DateTime.Now;
                
                if (Convert.ToSingle(dt.Second.ToString()) >= nextTime)
                {
                    //每秒嘀嗒
                    e.dida();
                    k++;
                }
                if (dt.ToLongTimeString().ToString() == time && Convert.ToSingle(dt.Second.ToString()) >= nextTime)
                {
                    //到响铃时间
                    e.Alarm();
                }
                nextTime = Convert.ToSingle(dt.Second.ToString()) + 1;
            }
            Console.WriteLine("设置时间运行结束");
        }
    }
}
